//
//  BlackbackgroundView.m
//  Qihuo
//
//  Created by Vencoo on 13-11-7.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//

#import "BlackbackgroundView.h"
#import "EmergencyViewController.h"
#import "Appinfomation.h"
@implementation BlackbackgroundView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       UIImageView* greyView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,1024,768)];
        greyView.userInteractionEnabled = YES;
        greyView.image = [UIImage imageNamed:@"黑底1"];
        [self addSubview:greyView];
        
       UIImage* backgroundimage = [UIImage imageNamed:@"37F底框"];
       UIImageView * addImageView = [[UIImageView alloc]initWithImage:backgroundimage];
        addImageView.frame = CGRectMake((greyView.frame.size.width - backgroundimage.size.width)/2, (greyView.frame.size.height - backgroundimage.size.height)/2, backgroundimage.size.width, backgroundimage.size.height);
        addImageView.userInteractionEnabled = YES;
        [greyView addSubview:addImageView];
        
        UIImage *closeImage = [UIImage imageNamed:@"关闭"];
        UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [closeBtn setImage:closeImage forState:UIControlStateNormal];
        closeBtn.frame = CGRectMake(backgroundimage.size.width - closeImage.size.width - 20, 20, closeImage.size.width, closeImage.size.height);
        [closeBtn addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
        [addImageView addSubview:closeBtn];
        closeBtn.tag = 250;
        
        UIImage *whiteimage = [UIImage imageNamed:@"弹出出灰底"];
        _whiteView = [[UIImageView alloc]initWithImage:whiteimage];
        _whiteView.frame = CGRectMake((backgroundimage.size.width - whiteimage.size.width)/2, 79, whiteimage.size.width, whiteimage.size.height);
        [addImageView addSubview:_whiteView];
        _whiteView.userInteractionEnabled = YES;

        [Appinfomation shareIstance].whiteView = self.whiteView;
        
    }
    return self;
}
- (void)hidden
{
    if ([Appinfomation shareIstance].strongXunJianCount == 110)
    {
        [self.delegate.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        self.hidden = YES;
        self.delegate.navigationController.navigationBar.hidden = NO;
        [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
    }
}

@end
